package com.sgb.goods.view.adapter;

import android.view.View;

import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.databinding.GoodsItemSpecPriceBinding;
import com.sgb.goods.entity.GoodsPublishSkuListEntity;
import com.sgb.goods.utils.base.adapter.BaseCommonAdapter;

public class SpecPriceAdapter extends BaseCommonAdapter<GoodsPublishSkuListEntity> {

    public SpecPriceAdapter() {
        super(R.layout.goods_item_spec_price, BR.viewModel);
    }

    @Override
    protected void convert(BaseViewHolder baseHolder, ViewDataBinding dataBinding, GoodsPublishSkuListEntity entity) {

        GoodsItemSpecPriceBinding mDataBinding = (GoodsItemSpecPriceBinding) dataBinding;

        mDataBinding.etPrice.setText(entity.money);
        if (baseHolder.getLayoutPosition() == 0) {
            //第一条数据隐藏这条线
            mDataBinding.tvLine.setVisibility(View.GONE);
        } else {
            mDataBinding.tvLine.setVisibility(View.VISIBLE);
        }
        if (entity.isFill) {
            mDataBinding.llTitle.setVisibility(View.GONE);
        } else {
            mDataBinding.llTitle.setVisibility(View.VISIBLE);
            String name = "";
            if (entity.list != null) {
                for (int i = 0; i < entity.list.size(); i++) {
                    if (i != entity.list.size() - 1) {
                        name = name + entity.list.get(i).getVal() + "-";
                    } else {
                        name = name + entity.list.get(i).getVal();
                    }
                }
            }
            mDataBinding.tvName.setText(name);
            mDataBinding.tvRemove.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    getData().remove(baseHolder.getLayoutPosition());
                    notifyDataSetChanged();
                }
            });
        }
    }
}
